/*
 * @FilePath: index.ts
 * @@author: wjj
 * @Date: 2025-04-24 20:34:19
 * @@Description: new js file
 */
//用户管理模块的接口
import request from '@/utils/request'
import type {
  UserResponseData,
  User,
  AllRoleResponseData,
  SetRoleData,
} from './type'
//枚举地址
enum API {
  //获取全部已有用户账号信息
  ALLUSER_URL = '/admin/acl/user/',

  //更新已有的用户账号
  UPDATEUSER_URL = '/nimi/auth/acl_user/',

  DELETEUSER_URL = '/nimi/auth/acl_user/',
  //批量删除的接口
  DELETEALLUSER_URL = '/nimi/auth/acl_user',
}

//获取用户账号信息的接口
export const reqUserInfo = (page: number, limit: number, username: string) =>
  request.get<any, UserResponseData>(
    // API.ALLUSER_URL + `${page}/${limit}/?username=${username}`,

    `/nimi/auth/acl/user?page=${page}&page_size=${limit}&username=${username}`,
  )
//添加用户与更新已有用户的接口
export const reqAddOrUpdateUser = (data: User) => {
  console.log(data.nickname)
  console.log('9++++')
  //携带参数有ID更新
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL + data.id, data)
  } else {
    return request.post<any, any>('/nimi/auth/user/regist/', data)
    // return request.post<any, any>(API.ADDUSER_URL, data)
  }
}
//获取全部职位以及包含当前用户的已有的职位
export const reqAllRole = (userId: number) =>
  // request.get<any, AllRoleResponseData>(API.ALLROLEURL + userId)
  request.get<any, AllRoleResponseData>(
    '/nimi/auth/acl/user/toAssign?user_id=' + userId,
  )
//分配职位user/doAssignRole
export const reqSetUserRole = (data: SetRoleData) =>
  // request.post<any, any>(API.SETROLE_URL, data)
  request.post<any, any>('/nimi/auth/acl/user/doAssignRole', data)
//删除某一个账号的信息
export const reqRemoveUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + userId)
//批量删除的接口
export const reqSelectUser = (idList: number[]) =>
  request.post(API.DELETEALLUSER_URL, { data: idList })
